/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.discount.web.controller.api;


import com.medusa.gruul.common.core.util.PageUtils;
import com.medusa.gruul.common.core.util.Result;
import com.medusa.gruul.discount.api.model.vo.api.ApiMemberCouponVo;
import com.medusa.gruul.discount.service.api.IApiMemberCouponService;
import com.medusa.gruul.goods.api.model.param.api.ApiProductParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 小程序客户优惠劵 前端控制器
 * </p>
 *
 * @author lcysike
 * @since 2019-12-09
 */
@RestController
@RequestMapping("/api/member/coupon")
public class ApiMemberCouponController {

    @Autowired
    private IApiMemberCouponService apiMemberCouponService;

    /**
     * 获取用户优惠劵信息
     */
    @GetMapping("/getByUserId")
    @ApiOperation(value = "用户优惠劵信息列表")
    public Result<List<ApiMemberCouponVo>> getMemberCouponListByUserId() {
        List<ApiMemberCouponVo> apiMemberCouponVos = apiMemberCouponService.getMemberCouponListByUserId();
        return Result.ok(apiMemberCouponVos);
    }

    /**
     * 优惠劵领取
     */
    @PostMapping("/receiveCoupon/{id}")
    @ApiOperation(value = "优惠劵领取")
    public Result receiveCoupon(@ApiParam(value = "优惠劵id", required = true) @PathVariable(name = "id") Long couponId) {
        return apiMemberCouponService.receiveCoupon(couponId);
    }

    /**
     * 一键领取优惠劵
     */
    @PostMapping("/receiveCoupon/some/{ids}")
    @ApiOperation(value = "一键领取优惠劵")
    public Result receiveSomeCoupon(@ApiParam(value = "优惠劵ids", required = true) @PathVariable(name = "ids") Long[] ids) {
        apiMemberCouponService.receiveSomeCoupon(ids);
        return Result.ok();
    }

    /**
     * 积分优惠劵兑换
     */
    @PostMapping("/exchangeCoupon/{id}")
    @ApiOperation(value = "积分优惠劵兑换")
    public Result exchangeCoupon(@ApiParam(value = "优惠劵id", required = true) @PathVariable(name = "id") Long couponId) {
        apiMemberCouponService.exchangeCoupon(couponId);
        return Result.ok();
    }

    /**
     * 获取单张客户已领取优惠券可使用商品列表
     */
    @GetMapping("/alive/product/list/{id}")
    @ApiOperation(value = "获取单张客户已领取优惠券可使用商品列表")
    public Result<PageUtils> getProductPageBySingleCoupon(@ApiParam(value = "客户优惠劵id", required = true) @PathVariable("id") Long id,
                                                          ApiProductParam apiProductParam) {
        PageUtils pageUtils = new PageUtils(apiMemberCouponService.getProductPageBySingleCoupon(id, apiProductParam));
        return Result.ok(pageUtils);
    }

}
